package org.dromara.run.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.run.domain.bo.ScheduleBo;
import org.dromara.run.domain.vo.ScheduleVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.run.domain.vo.ScoreConfigVo;
import org.dromara.run.domain.bo.ScoreConfigBo;
import org.dromara.run.service.IScoreConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 阳光跑成绩配置
 *
 * @author chl
 * @date 2024-08-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/run/scoreConfig")
public class ScoreConfigController extends BaseController {

    private final IScoreConfigService scoreConfigService;

    /**
     * 查询阳光跑成绩配置列表
     */
    @SaCheckPermission("run:scoreConfig:list")
    @GetMapping("/list")
    public TableDataInfo<ScoreConfigVo> list(ScoreConfigBo bo, PageQuery pageQuery) {
        return scoreConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询阳光跑成绩配置列表
     *
     * @param bo 查询主体
     */
    @SaCheckPermission("run:scoreConfig:query")
    @GetMapping("/infoList")
    public R<List<ScoreConfigVo>> getInfoList(ScoreConfigBo bo) {
        return R.ok(scoreConfigService.queryList(bo));
    }

    /**
     * 导出阳光跑成绩配置列表
     */
    @SaCheckPermission("run:scoreConfig:export")
    @Log(title = "阳光跑成绩配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ScoreConfigBo bo, HttpServletResponse response) {
        List<ScoreConfigVo> list = scoreConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "阳光跑成绩配置", ScoreConfigVo.class, response);
    }

    /**
     * 获取阳光跑成绩配置详细信息
     *
     * @param scoreConfigId 主键
     */
    @SaCheckPermission("run:scoreConfig:query")
    @GetMapping("/{scoreConfigId}")
    public R<ScoreConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long scoreConfigId) {
        return R.ok(scoreConfigService.queryById(scoreConfigId));
    }

    /**
     * 新增阳光跑成绩配置
     */
    @SaCheckPermission("run:scoreConfig:add")
    @Log(title = "阳光跑成绩配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ScoreConfigBo bo) {
        return toAjax(scoreConfigService.insertByBo(bo));
    }

    /**
     * 修改阳光跑成绩配置
     */
    @SaCheckPermission("run:scoreConfig:edit")
    @Log(title = "阳光跑成绩配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ScoreConfigBo bo) {
        return toAjax(scoreConfigService.updateByBo(bo));
    }

    /**
     * 删除阳光跑成绩配置
     *
     * @param scoreConfigIds 主键串
     */
    @SaCheckPermission("run:scoreConfig:remove")
    @Log(title = "阳光跑成绩配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scoreConfigIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] scoreConfigIds) {
        return toAjax(scoreConfigService.deleteWithValidByIds(List.of(scoreConfigIds), true));
    }
}
